import {
  BackendEnumsKeyValPair,
  defaultInitialState,
  KfAppInitialState,
  KfServicesCascaderPickerDataType,
  KfServicesFlatPickerDataType,
  KfServicesTreePickerDataType
} from "kf-web-library";
import {Settings as LayoutSettings} from "@ant-design/pro-components";
import * as API from "@/services";
import {KfBizDataCascaderPickerProps} from "@kf-web-library/forms";
import {KfBizDataFlatPickerProps, KfBizDataTreePickerProps} from "@kf-web-library/forms/src";


export type AppServicesFlatPickerDataType = KfServicesFlatPickerDataType
export type AppServicesFlatPickerDataTypeRecord = Partial<Record<AppServicesFlatPickerDataType, Partial<KfBizDataFlatPickerProps>>>;


export type AppServicesTreePickerDataType = KfServicesTreePickerDataType
export type AppServicesTreePickerDataTypeRecord = Partial<Record<AppServicesTreePickerDataType, Partial<KfBizDataTreePickerProps>>>;


export type AppServicesCascaderPickerDataType = KfServicesCascaderPickerDataType
export type AppServicesCascaderPickerDataTypeRecord = Partial<Record<AppServicesCascaderPickerDataType, Partial<KfBizDataCascaderPickerProps>>>;


export interface AppInitialState extends KfAppInitialState {
  loading?: boolean;
  //布局设置参数
  settings?: Partial<LayoutSettings>;
  //当前登录认证信息
  currentAuthInfo?: API.AuthInfo | null;
  //当前登录用户信息
  currentUserInfo?: API.User;
  fetchUserInfo?: () => Promise<API.User | undefined>;
  fetchBackendEnums?: () => Promise<BackendEnumsKeyValPair | undefined>;
  //登录后需要fetch的信息 (用户信息, 后端枚举, 展示菜单定义)
  fetchLoggedInfo?: () => Promise<any>;

  services?: {
    flatPickers?: AppServicesFlatPickerDataTypeRecord;    //(平)业务选取组件定义集
    treePickers?: AppServicesTreePickerDataTypeRecord;    //(树)业务选取组件定义集
    cascaderPickers?: AppServicesCascaderPickerDataTypeRecord;    //(级联)业务选取组件定义集
  }

}


export const appInitialStateImpl: AppInitialState = {
  ...defaultInitialState,
  services: {
    ...defaultInitialState.services,
    flatPickers: {
      ...defaultInitialState.services?.flatPickers,
    },
    treePickers: {
      ...defaultInitialState.services?.treePickers,
    }
  }
}
